package leetcode;

import java.util.Arrays;

public class Day19 {
    public int removeElement(int[] nums, int val) {
        int n=nums.length;
        int[] ret=new int[n];
        int r=0;
        int k=0;
        for (int i=0;i<n;i++){
            if(nums[i]!=val){
                ret[r]=nums[i];
                k++;
                r++;
            }
        }
        for (int i=0;i<n;i++){
            nums[i]=ret[i];
        }
        return k;
    }
    public int removeDuplicates1(int[] nums) {
    int i=0;
    int j=0;
    int k=0;
    int n=nums.length;
    int[] ret=new int[n];
    while (j<n){
        if(i==j){
            nums[k]=nums[i];
            j++;
            k++;
        }
        if(nums[i]==nums[j]){
            j++;
        }else {
            i=j;
        }
    }
    nums= Arrays.copyOf(nums,k);
    return k;
    }
    public int removeDuplicates(int[] nums) {
        int slow=2;
        int fast=2;
        int n=nums.length;
        if(n<=2){
            return n;
        }
        while (fast<n){
            if(nums[fast]!=nums[slow-2]){
                nums[slow]=nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }

}
class MyBlockingqueue{
    String[] arr=new String[10];
    private volatile int beg=0;
    private volatile int end=0;
    private volatile int size=0;
    public void put(String elment) throws InterruptedException {
        synchronized (this){
            if(size==arr.length){
                this.wait();
                return;
            }
            arr[end]=elment;
            end++;
            size++;
            this.notify();
            if(end==arr.length){
                end=0;
            }
        }
    }
    public String take() throws InterruptedException {
        synchronized (this){
            if (size==0){
                this.wait();
            }
            String ret=arr[beg];
            beg++;
            size--;
            this.notify();
            if(beg==arr.length){
                beg=0;
            }
            return ret;
        }
    }
}